class Solution {//leetcode662——二叉树的最大宽度
public:
    int widthOfBinaryTree(TreeNode* root) {
        vector<pair<TreeNode*,unsigned int>> que;
        int front=0,back=0;
        que.push_back(make_pair(root,0));
        back++;
        unsigned int max_width=0;
        while(front!=back){
            auto &[x1,y1]=que[front];
            auto &[x2,y2]=que[back-1];
            max_width=max(max_width,y2-y1+1);
            int level=back-front;
            for(int i=0;i<level;i++){
                auto &[x,y]= que[front++];
                if(x->left){
                    que.push_back(make_pair(x->left,y*2+1));
                    back++;
                }
                if(x->right){
                    que.push_back(make_pair(x->right,y*2+2));
                    back++;
                }  
            }
        }
        return max_width;

    }
};